<template>
  <div id="app" :class="themeStore.currentThemeId">
    <div class="theme-transition-overlay" ></div>
    <router-view></router-view>
  </div>
</template>

<script setup>
import {  ref, onMounted, watch } from 'vue';
import { useThemeStore } from './stores/modules/theme';

const themeStore = useThemeStore();

const isThemeChanging = ref(false);

// 监听主题变化，添加过渡动画
watch(() => themeStore.currentThemeId, (newTheme, oldTheme) => {
  if (newTheme !== oldTheme) {
    isThemeChanging.value = true;
    setTimeout(() => {
      isThemeChanging.value = false;
    }, 500); // 与CSS过渡时间匹配
  }
});

onMounted(() => {
  // 初始化主题
  themeStore.initTheme();

  // 监听系统主题变化
  const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
  mediaQuery.addEventListener('change', () => {
    if (themeStore.autoThemeMode) {
      const isDarkMode = mediaQuery.matches;
      themeStore.setTheme(isDarkMode ? 'dark' : 'light');
    }
  });
});
</script>

<style scoped>
/* Base styles with CSS variables */
:root {
  --primary: #1890ff;
  --primary-dark: #096dd9;
  --success: #52c41a;
  --warning: #faad14;
  --error: #f5222d;
  --border: #e8e8e8;
  --text: #333333;
  --text-secondary: #666666;
  --background: #f0f2f5;
  --component-background: #ffffff;
  --shadow-color: rgba(0, 0, 0, 0.1);

  /* Additional variables */
  --sidebar-width: 240px;
  --sidebar-collapsed-width: 80px;
  --header-height: 64px;
  --border-radius: 4px;
  --transition-duration: 0.3s;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--background);

  transition: background-color var(--transition-duration), color var(--transition-duration);
}

/* 主题过渡动画 */
.theme-transition-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(255, 255, 255, 0);
  pointer-events: none;
  z-index: 9999;
  transition: background-color 0.5s ease;
}

.theme-transition-overlay.active {
  background-color: rgba(255, 255, 255, 0.5);
}

.dark .theme-transition-overlay.active {
  background-color: rgba(0, 0, 0, 0.5);
}

/* 全局过渡效果 */
.theme-transition,
.btn,
input,
select,
textarea,
.card,
.modal-content,
.sidebar,
.top-bar {
  transition: background-color var(--transition-duration),
              color var(--transition-duration),
              border-color var(--transition-duration),
              box-shadow var(--transition-duration);
}

/* 按钮样式 */
.btn {
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  cursor: pointer;
  font-size: 1rem;
  transition: all var(--transition-duration) ease;
  border: none;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: #6c757d;
  color: white;
}

.dark .btn-secondary {
  background-color: #4c5258;
}

.btn-secondary:hover {
  background-color: #5a6268;
}

.dark .btn-secondary:hover {
  background-color: #3a4045;
}

.btn-danger {
  background-color: var(--error);
  color: white;
}

.btn-danger:hover {
  opacity: 0.9;
}

.btn-warning {
  background-color: var(--warning);
  color: #212529;
}

.dark .btn-warning {
  color: #f0f0f0;
}

.btn-warning:hover {
  opacity: 0.9;
}

.btn-info {
  background-color: #17a2b8;
  color: white;
}

.btn-info:hover {
  opacity: 0.9;
}

.btn-success {
  background-color: var(--success);
  color: white;
}

.btn-success:hover {
  opacity: 0.9;
}

.btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.875rem;
}

/* 表单元素样式 */
input, select, textarea {
  background-color: var(--component-background);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--border-radius);
  padding: 0.5rem;
  font-size: 1rem;
  transition: border-color var(--transition-duration);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}

/* 暗黑模式样式 */
.dark input,
.dark select,
.dark textarea {
  background-color: #2a2a2a;
  color: var(--text);
  border-color: var(--border);
}

.dark input:focus,
.dark select:focus,
.dark textarea:focus {
  border-color: var(--primary);
}

.dark .modal-content,
.dark .card {
  background-color: var(--component-background);
  color: var(--text);
}

.dark table {
  color: var(--text);
}

.dark th {
  background-color: #2a2a2a;
}

.dark tr:nth-child(even) {
  background-color: #2a2a2a;
}

.dark tr:hover {
  background-color: #3a3a3a;
}

/* 卡片样式 */
.card {
  background-color: var(--component-background);
  border-radius: var(--border-radius);
  box-shadow: 0 2px 8px var(--shadow-color);
  padding: 1rem;
  margin-bottom: 1rem;
  color: var(--text);
}

/* 表格样式 */
table {
  width: 100%;
  border-collapse: collapse;
  color: var(--text);
}

th, td {
  border: 1px solid var(--border);
  padding: 0.75rem;
  text-align: left;
}

th {
  background-color: rgba(0, 0, 0, 0.02);
  font-weight: bold;
  color: var(--primary);
}

.dark th {
  background-color: rgba(255, 255, 255, 0.05);
}

tr:nth-child(even) {
  background-color: rgba(0, 0, 0, 0.01);
}

.dark tr:nth-child(even) {
  background-color: rgba(255, 255, 255, 0.02);
}

tr:hover {
  background-color: rgba(0, 0, 0, 0.03);
}

.dark tr:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

/* 模态框样式 */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: var(--component-background);
  border-radius: var(--border-radius);
  box-shadow: 0 4px 12px var(--shadow-color);
  max-width: 90%;
  max-height: 90vh;
  overflow: auto;
  color: var(--text);
}

.modal-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-body {
  padding: 1rem;
}

.modal-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 200px;
  }

  .btn {
    padding: 0.4rem 0.8rem;
  }
}
</style>


